import { $helper } from '@/utils';
import { $Platform } from '@/utils/const/env';
import { ref } from 'vue';
export default () => {
    const PLATFORM = ref<PlatformType>({
		// #ifdef H5
		platform: $Platform.H5, 
		// #endif
		// #ifdef APP
		platform: $Platform.APP,
		// #endif
		// #ifdef MP-WEIXIN
		platform: $Platform.MP_WEIXIN,
		// #endif
		// #ifdef MP-ALIPAY
		platform: $Platform.MP_ALIPAY,
		// #endif
		// #ifdef MP-BAIDU
		platform: $Platform.MP_BAIDU,
		// #endif
		// #ifdef MP-TOUTIAO
		platform: $Platform.MP_TOUTIAO,
		// #endif
		// #ifdef MP-QQ
		platform: $Platform.MP_QQ,
		// #endif
		// #ifdef MP-360
		platform: $Platform.MP_360,
		// #endif
		// #ifdef MP-KUAISHOU
		platform: $Platform.MP_KUAISHOU,
		// #endif
		platforms: [],
		statusBarHeight:0,
		windowWidth:375
    });
	// 设置平台某一项信息，key为PlatformType中定义的属性，value为对应的值
	const set=<K extends keyof PlatformType&string>(key:K,value:PlatformType[K])=>{
		PLATFORM.value[key]=value
	}
	const checkPlatform = () => {
	    PLATFORM.value.platforms.push(PLATFORM.value.platform);
	    $helper.platforms().forEach((item:string) => {
	        PLATFORM.value.platforms.push(item);
	    });
		const info=$helper.info()
		set('statusBarHeight',info.statusBarHeight)
		set('windowWidth',info.windowWidth)
	}
    return {
        PLATFORM,
		checkPlatform,
		set
    };
}